package com.xxxx.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/*
 * 	request作用域
 * 		通过该对象可以在一个请求中传递数据,作用范围: 在一次请求中有效,即服务器跳转有效，(请求转发跳转时有效)
 * 		//设置域对象内容
 * 		request.setAttribute(String name,Object value);
 * 		//获取域对象内容
 * 		request.getAttribute(String name);
 * 		//删除域对象内容
 * 		request.removeAttribute(String name);
 */



@WebServlet("/S5")
public class Servlet05request extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			System.out.println("Servlet05.....");
			
			//设置域对象内容
		request.setAttribute("name", "admin");
		request.setAttribute("age", 18);
		List<String>list = new ArrayList<>();
		list.add("aaa");
		list.add("bbb");
		request.setAttribute("list", list);
		
		//请求转发跳转到Servlet06
		//request.getRequestDispatcher("S6").forward(request, response);
		//请求转发跳转到jsp 并通过域对象传递数据
		request.getRequestDispatcher("index.jsp").forward(request, response);
	}
		
}
